//! \file pairsocket.hpp
//! \brief Purewell Library Pair Socket Header
//! \author Yubin Lim (purewell@gmail.com)
//! \since 2008-01-25

#ifndef __PAIRSOCKET_HPP__
#define __PAIRSOCKET_HPP__

#include "pairfile.hpp"
#include "socket.hpp"

namespace purewell
{

//! \brief Pair socket.
class PWPairSocket : public PWPairFile
{
public:
	//! \brief Initialize pair socket.
	//! \param[in] name Socket file name.
	//! \param[in] flags Flags.
	//! \param[in] omode Open modes.
	virtual bool initialize(const char* name, int flags, int omode);

	//! \brief Set default file descriptor by index.
	//! \param[in] idx Index to set default fd.
	void setDefaultFile(size_t idx);

	//! \brief Get default file descriptor index.
	//! \return Default file descriptor index.
	size_t getDefaultFile(void) const;

public:
	//! \brief Read buffer from socket.
	//! \param[out] buf Buffer.
	//! \param[in] blen Buffer length.
	//! \return Operated size or -1.
	virtual ssize_t read(void* buf, size_t blen);

	//! \brief Write buffer to socket.
	//! \param[in] buf Buffer.
	//! \param[in] blen Buffer length.
	//! \return Operated size or -1.
	virtual ssize_t write(const void* buf, size_t blen);

public:
	explicit PWPairSocket();
	virtual ~PWPairSocket();

protected:
	size_t m_op_idx;	//!< Default index.

};

};

#endif//!__PAIRSOCKET_HPP__

